home *** CD-ROM | disk | FTP | other *** search
/ CBM Funet Archive / cbm-funet-archive-2003.iso / cbm / demodisks / drives / 1581-demo.lzh / rel file example (.txt) < prev    next >
Commodore BASIC  |  1994-10-19  |  5KB  |  142 lines

  1. 10 rem   use this program to learn how
  2. 20 rem   create and use relative files.
  3. 30 rem   it is flexible enough for you
  4. 40 rem   to customize it for your use.
  5. 50 rem
  6. 55 poke53280,0:poke53281,0
  7. 75 gosub1460
  8. 80 ll$=chr$(13)  :rem  this is the field delimiter used when writing records
  9. 90 input"[155]  what is the file name";nm$:  rem  maximum 16 character name.
  10. 100 iflen(nm$)>0andlen(nm$)<17then120
  11. 110 print"[145][145][145]":goto90
  12. 120 input"[155]  on what device number";dv
  13. 130 open15,dv,15,"i0": rem  initialize the disk drive.
  14. 140 open 8,dv,8,"0:"+(nm$)
  15. 150 input#15,e,e$,a,b   :rem  read the error channel.
  16. 160 if e=62 then 200
  17. 170 if e=0 then 180:printe,e$,a,b:goto 1270
  18. 180 print"[155]   (file exists)"
  19. 190 goto 280
  20. 200 print"[155]   (new file)"
  21. 210 close8
  22. 220 input"[155]  how many characters in each record";ln  :rem    maximum 254.
  23. 230 ln=int(ln):ifln>0andln<255then250
  24. 240 print"[145][145][145]":goto220
  25. 250 open8,dv,8,"0:"+(nm$)+",l,"+chr$(ln)
  26. 260 gosub 1110
  27. 280 print"[155]    do you want to :        "
  28. 290 printspc(7)"r[155]ead a record"
  29. 300 printspc(7)"w[155]rite a record"
  30. 310 printspc(7)"s[155]et up a file"
  31. 320 printspc(7)"q[155]uit "
  32. 330 print
  33. 340 a$=""
  34. 350 geta$
  35. 360 if a$="r" then 420
  36. 370 if a$="w" then 640
  37. 380 if a$="s" then 890
  38. 390 if a$="q" then 1050
  39. 400 goto350
  40. 410 :
  41. 420 rem  this section positions to and reads a record.
  42. 425 gosub 1460:print
  43. 430 input"[155]read what record number";rn
  44. 440 gosub1060 :rem  calculate the low byte/high byte pointer.
  45. 450 print#15,"p"+chr$(96+8)+chr$(rl)+chr$(rh)+chr$(1) :rem  position command
  46. 460 gosub 1110 :rem  check the error channel
  47. 470 if e=50 thenprint"[155]record number too large":goto560
  48. 480 input#8,aa$,bb$,cc$,dd$,ee$ :rem  read in the fields.
  49. 490 gosub 1110 :rem  check the error channel
  50. 500 print"[155]record number";rn;"[157] contains:":print
  51. 510 printspc(8)"[155]name: ";aa$
  52. 520 printspc(5)"[155]address: ";bb$
  53. 530 printspc(8)"[155]city: ";cc$
  54. 540 printspc(7)"[155]state: ";dd$
  55. 550 printspc(4)"[155]zip code: ";ee$
  56. 560 print#15,"p"+chr$(96+8)+chr$(rl)+chr$(rh)+chr$(1):rem  reposit'n for safety
  57. 570 gosub 1110 :rem  check the error channel
  58. 580 print"[155]read another record?";:a$=""
  59. 590 geta$:if (a$<>"y") and (a$<>"n") then 590
  60. 600 print
  61. 610 if a$="y"thengoto425
  62. 620 gosub1460:goto280 :rem do main menu
  63. 630 :
  64. 640 rem  this section positions to and writes a record.
  65. 645 gosub1460:print
  66. 650 input"[155]write what record number";rn:print
  67. 660 input"[155]      name: ";aa$ :rem  change the prompts to ask for data needed
  68. 670 input"[155]   address: ";bb$ :rem  in your particular application.
  69. 680 input"[155]      city: ";cc$ :rem  any number of fields can be used as long as
  70. 690 input"[155]     state: ";dd$ :rem  they fit within the record length you
  71. 700 input"[155]  zip code: ";ee$ :print:rem  specified when creating the file.
  72. 710 rc$=aa$+ll$+bb$+ll$+cc$+ll$+dd$+ll$+ee$
  73. 720 rem  rc$ is the string containing all the fields for the record.
  74. 730 rem  remember the max length for rc$ is 254 characters.
  75. 740 gosub1060 :rem  calculate the low byte/high byte pointer.
  76. 750 print#15,"p"+chr$(96+8)+chr$(rl)+chr$(rh)+chr$(1) :rem  position command
  77. 760 gosub 1110 :rem  check the error channel
  78. 770 if e=50 thenprint"[155]the dos will expand the file now"
  79. 780 print#8,rc$  :rem  write the record
  80. 790 gosub 1110 :rem  check the error channel
  81. 800 print#15,"p"+chr$(96+8)+chr$(rl)+chr$(rh)+chr$(1) :rem reposit'n for safety
  82. 810 gosub 1110 :rem  check the error channel
  83. 820 print
  84. 830 print"[155]write another record?";:a$=""
  85. 840 geta$:if (a$<>"y") and (a$<>"n") then 840
  86. 860 if a$="y"then645
  87. 870 gosub1460:goto280 :rem  do main menu
  88. 880 :
  89. 890 rem  this section positions to and writes the highest record number.
  90. 900 rem  although not entirely necessary, writing and updating long files
  91. 910 rem  is speeded when this procedure is used.  this will cause the
  92. 920 rem  dos side sector list to be created entirely at the start rather
  93. 930 rem  than being appended for each new higher record number.
  94. 940 print"[155]what is the highest record number"
  95. 950 input"[155]you want to use";rn
  96. 960 gosub1060 :rem  calculate the low byte/high byte pointer.
  97. 970 print#15,"p"+chr$(96+8)+chr$(rl)+chr$(rh)+chr$(1) :rem  position command
  98. 980 gosub 1110 :rem  check the error channel
  99. 990 if e=50 thenprint"[155]the dos will expand the file now"
  100. 1000 print#8,chr$(255) :rem
  101. 1010 gosub 1110 :rem  check the error channel
  102. 1020 print#15,"p"+chr$(96+8)+chr$(rl)+chr$(rh)+chr$(1) :rem reposit'n for safety
  103. 1030 gosub 1110 :rem  check the error channel
  104. 1040 goto280 :rem  go to the menu
  105. 1050 close8:close15:end
  106. 1060 rem  this subroutine calculates the record number pointer
  107. 1070 rem  in the low byte/high byte format.
  108. 1080 rem  rn (record number) is used to calculate rl and rh.
  109. 1090 rh=int(rn/256):rl=rn-(256*rh) : rem  rl is low -- rh is high.
  110. 1100 return
  111. 1110 rem   this is the disk drive error checking subroutine.
  112. 1120 input#15,e,e$,a,b   :rem  read the error channel.
  113. 1130 if e=0 then return  :rem  there is no error if e=0.
  114. 1140 rem   e=50 (record not present) any time a record number pointer is
  115. 1150 rem   positioned beyond the current highest record number.
  116. 1160 if e=50 then return
  117. 1170 if e<>51 then 1220
  118. 1180 print:print"[155]error-51, record too long."
  119. 1190 print"[155](return counts as a character)"
  120. 1200 gosub 1280
  121. 1210 return
  122. 1220 print"[155]there is an i/o problem"
  123. 1230 print"error number is";e,e$
  124. 1240 print"at track";a;"   sector";b
  125. 1250 if e=70 thenprint"[155]make sure you input the correct record"
  126. 1260 if e=70 thenprint"[155]length for an existing file name."
  127. 1270 close8:close15:end
  128. 1280 print"[155]computing allowable record length":print"   (please wait...)"
  129. 1290 if ln<>0 then 1330
  130. 1300 close8
  131. 1310 for ln=1 to 254:open8,dv,8,"0:"+(nm$)+",l,"+chr$(ln):input#15,e:ife=0then1330
  132. 1320 close 8:next ln:print"[155]unable to compute record length!":goto1270
  133. 1330 print"[145]                                                   "
  134. 1340 print"[145][155]allowable record length = ";ln
  135. 1350 return
  136. 1450 rem title subroutine
  137. 1460 print"[147][155]      [192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192]"
  138. 1465 printspc(6)"[159]  relative file demo   "
  139. 1470 printspc(6)"(name and address file)"
  140. 1475 print"[155]      [192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192]"
  141. 1480 return
  142.